package com.health.ts.controller.sysmanage;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.health.ts.constant.ApiResult;
import com.health.ts.entity.sysmanage.SysAuthority;
import com.health.ts.service.sysmanage.SysAuthorityService;
/**
 * 权限管理
 * @author Administrator
 */
@Controller
@RequestMapping(value = "/api/auth")
public class AuthorityController {
	
	@Autowired
	SysAuthorityService sysAuthorityService;
	
	/**
	 * 新建或修改权限
	 * @param auth
	 * @return
	 */
	@RequestMapping(value="/addAuth", method=RequestMethod.POST)
	public ApiResult addAuth(@RequestBody SysAuthority auth) {
		sysAuthorityService.saveOrUpdate(auth);
		return ApiResult.success();
    }
	
	/**
	 * 删除权限
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/{id}", method=RequestMethod.DELETE)
	public ApiResult deleteAuth(@PathVariable String id) {
		sysAuthorityService.removeById(id);
		return ApiResult.success();
    }
	
	/**
	 * 查询权限
	 * @return
	 */
	@RequestMapping(value = "/listAuth",method=RequestMethod.POST)
	public ApiResult listAuth() {
		List<SysAuthority> list = sysAuthorityService.list();
		return ApiResult.success(list);
	}
}
